package com.springboot.Service.musicIpml;

import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author 权哥
 * @version 1.0
 * @date 2022/5/18 23:40
 */
@Service
public class getJson {

    public String Json_data(String url) throws IOException {
        System.out.println(url);
        String AllJson="";
        //2.模拟发送请求
        URLConnection oc=new URL(url).openConnection();
        //		3.获取输入流
        InputStream in=oc.getInputStream();
        //		4.创建一个字符流写入文件
        BufferedReader br=new BufferedReader(new InputStreamReader(in,"UTF-8"));
        //5.读取字符，一行一行的读取
        while(true)
        {
            //一次性读取一行数据
            String rl=br.readLine();
            if(rl==null)
            {
                break;//如果读取的内容为空，就跳出循环
            }
            AllJson+=rl;
        }

        return AllJson;
    }


    public static void main(String[] args) throws IOException {
        System.out.println(new getJson().Json_data("https://autumnfish.cn/search?keywords=周杰伦"));
    }
}
